package com.wc.fortnight_blue_bridge.Q240518.C_矿石样本分析;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/18 19:40
 * @description https://www.lanqiao.cn/problems/18483/learning/?contest_id=185
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[][] a = new int[N][2];
    static int n, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        k = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i][0] = sc.nextInt();
            a[i][1] = i;
        }
        Arrays.sort(a, 1, n + 1, (o1, o2) -> {
            if (o1[0] == o2[0]) return o1[1] - o2[1];
            return o1[0] - o2[0];
        });
        int res = n + 1;
        for (int i = 1; i <= n; i++) {
            if (k - a[i][0] <= a[i][0]) break;
            int left = findLeft(k - a[i][0], i + 1);
            int right = findRight(k - a[i][0], i + 1);
            if (left == -1) continue;
            res = Math.min(Math.max(Math.min(a[i][1], n - a[i][1] + 1), Math.min(left, n - right + 1)), res);
        }
        out.println(res == n + 1 ? -1 : res);
        out.flush();
    }

    static int findLeft(int x, int l) {
        int r = n;
        while (l < r) {
            int mid = l + r >> 1;
            if (a[mid][0] >= x) r = mid;
            else l = mid + 1;
        }
        return a[l][0] == x ? a[l][1] : -1;
    }

    static int findRight(int x, int l) {
        int r = n;
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (a[mid][0] <= x) l = mid;
            else r = mid - 1;
        }
        return a[r][0] == x ? a[r][1] : -1;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
